package com.zzyy.study.completableFutureP;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * Description:
 * <p>
 * ClassName: CompletableFutureDemo1
 * date: 2021/2/25 16:21
 *
 * @author zzjx
 * @version 1.0
 * @since JDK 1.8
 */
public class CompletableFutureDemo1 {
    public static void main(String[] args) {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "zjx";
        }).whenComplete((v, e) -> {
            if (e == null) {
                System.out.println("******v: " + v);
            }
        }).exceptionally(e -> {
            e.printStackTrace();
            return null;
        });
        System.out.println("------main线程结束");

        future.join();
    }
}
